<?php
/**
 * 积分接口
 * 获取积分,获取积分等级
 * 验证用户身份token
 * @author Edwin
 */

namespace V1\Controller;

use Common\Controller\ApiController;

class IntegralController extends ApiController
{
    public function rest()
    {
        switch ($this->_method) {
            case 'get': // get请求处理代码
                $this->_get();
                break;
            case 'put': // put请求处理代码
                break;
            case 'post': // post请求处理代码
                break;
        }
    }

    /**
     * 输出积分以及以及分等级信息
     */
    private function _get()
    {
        $id = $this->userId;
        if ($id) {
            $map['userid'] = $id;
            $list = D('MemberProfile')->where($map)->field('score')->find();
            $msg = !empty($list) ? 'success' : 'query failed';
            $data['score'] = $list['score'];
            $data['score_level'] = D('Integral')->grade_type($list['score'],$id);
            if (!empty($list)) {
                $this->myApiPrint($msg, 200,$data);
            } else {
                $this->myApiPrint($msg,201,[]);
            }
        } else {
            $this->myApiPrint(C('ERROR_NUM')['218']);
        }
    }
}